import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import datetime
from datetime import date
import seaborn as sns
import warnings
warnings.filterwarnings('ignore')
# Read MA PPE data
df = pd.read_csv('MA_ppe_regions.csv', parse_dates=['Time'])
df.drop(['Total Persons Tested','Percent Positivity','Deaths','Hospitalized Total', 'Hospitalized ICU'], axis=1, inplace=True)
df = df.loc[df['Region']!='State Agency'].dropna(how='all')
df
...
SM = df.loc[df['Region']=='Southeastern Massachusetts']
SM_CC = SM.dropna()
categories = ['N95s/KN95s', 'Masks', 'Gowns', 'Gloves', 'Ventilators']
for category in categories:
SM_CC['{} %'.format(category)] = SM_CC[category]/SM_CC[category].iloc[-1] * 100
fig, axes = plt.subplots(2, 3, figsize=(25,15))
for ax, category in zip(axes.flatten(), categories):
sns.distplot(SM_CC[category].diff(), ax=ax)
ax.set_xlabel(category, fontsize=15)
fig.delaxes(axes[1,2])
SM_CC
Distplot of PPE Growth
# Confirmed cases vs PPE distribution
fig, axes = plt.subplots(2,1,figsize=(15,14))
percentages = ['N95s/KN95s %', 'Masks %', 'Gowns %', 'Gloves %', 'Ventilators %']
for category in categories:
axes[0].plot('Time', category, data=SM_CC, marker='.', markersize=10)
axes[0].set_xlabel('Date', fontsize=15)
axes[0].set_ylabel('The Number of PPE Distribution', fontsize=15)
axes[0].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020, 9,9)])
axes[0].tick_params(direction='out', length=6, width=2, labelsize=10)
axes[0].legend()
axes[0].set_title('PPE Distribution vs Confirmed Cases in SM', fontsize=20)
ax1 = axes[0].twinx()
ax1.plot('Time', 'Confirmed Cases', data=SM_CC, color='y', linestyle='--', linewidth=3, label='Confirmed Cases')
ax1.set_ylabel('Confirmed Cases', fontsize=15)
ax1.tick_params(direction='out', length=6, width=2, labelsize=10)
ax1.legend(loc='upper right')
for percentage in percentages:
axes[1].plot('Time', percentage, data=SM_CC, marker='.', markersize=10)
axes[1].set_xlabel('Date', fontsize=15)
axes[1].set_ylabel('PPE Distribution %', fontsize=15)
axes[1].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020, 9,9)])
axes[1].tick_params(direction='out', length=6, width=2, labelsize=10)
axes[1].legend()
axes[1].set_title('PPE Distribution Percentage vs Confirmed Cases in SM', fontsize=20)
ax2 = axes[1].twinx()
ax2.plot('Time', 'Confirmed Cases', data=SM_CC, color='y', linestyle='--', linewidth=3, label='Confirmed Cases')
ax2.set_ylabel('Confirmed Cases', fontsize=15)
ax2.tick_params(direction='out', length=6, width=2, labelsize=10)
ax2.legend(loc='upper right')
plt.show()
pd.set_option("display.max_rows", None, "display.max_columns", None)
# Calculate the ratio of cumulative PPE data to cumulative confirmed cases data (Ratio 1)
for category in categories:
SM_CC['{} Ratio 1'.format(category)] = SM_CC[category]/SM_CC['Confirmed Cases']
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 2)
# (Interval=2 weeks, one week before + the week itself)
SM_CC['Confirmed Cases(ma1)'] = SM_CC['Confirmed Cases'].rolling(window=2,center=False).mean()
SM_CC.iloc[0,-1] = (6065 + 9446) / 2
for category in categories:
SM_CC['{} Ratio 2'.format(category)] = SM_CC[category]/SM_CC['Confirmed Cases(ma1)']
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 3)
# (Interval=2 weeks, one week after + the week itself)
SM_CC['Confirmed Cases(ma2)'] = SM_CC['Confirmed Cases'].rolling(window=2,center=False).mean().shift(-1)
for category in categories:
SM_CC['{} Ratio 3'.format(category)] = SM_CC[category]/SM_CC['Confirmed Cases(ma2)']
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 4)
# (Interval=3 weeks, one week before + one week after + the week itself)
SM_CC['Confirmed Cases(ma3)'] = SM_CC['Confirmed Cases'].rolling(window=3,center=False).mean().shift(-1)
SM_CC.iloc[0,-1] = (6065+9446+11616)/3
for category in categories:
SM_CC['{} Ratio 4'.format(category)] = SM_CC[category]/SM_CC['Confirmed Cases(ma3)']
# Calculate the ratio of delta PPE data to delta confirmed cases data (Ratio 5)
for category in categories:
SM_CC['{} Ratio 5'.format(category)] = SM_CC[category].diff()/SM_CC['Confirmed Cases'].diff()
# Calculate the ratio of delta PPE data to moving average delta confirmed cases data (Ratio 6)
for category in categories:
SM_CC['{} Ratio 6'.format(category)] = SM_CC[category].diff()/SM_CC['Confirmed Cases'].diff().rolling(window=2,center=False).mean()
# SM_CC
# Plot the Ratio of PPE to Confirmed Cases
RATIO1 = []
RATIO2 = []
RATIO3 = []
RATIO4 = []
RATIO5 = []
RATIO6 = []
RATIOS = [RATIO1, RATIO2, RATIO3, RATIO4, RATIO5, RATIO6]
for RATIO in RATIOS:
for category in categories:
RATIO.append('{} Ratio {}'.format(category, RATIOS.index(RATIO)+1))
fig, ax = plt.subplots(1,1,figsize=(14, 6))
color = ['b', 'g', 'r', 'c', 'm']
for category in categories:
ax.plot('Time', category, data=SM_CC, color=color[categories.index(category)], linewidth=3, label=category, marker='.', markersize=12)
ax.set_xlabel('Date', fontsize=15)
ax.set_ylabel('The number of PPE', fontsize=15)
ax.set_xlim([datetime.date(2020, 4, 29), datetime.date(2020, 9,9)])
ax.legend(loc='best')
ax.set_title('The Ratio of PPE Dstribution to Confirmed Cases in Southeastern Massachusetts', fontsize=20)
ax1 = ax.twinx()
for ratio in RATIO1:
ax1.plot('Time', ratio, data=SM_CC, color=color[RATIO1.index(ratio)], linestyle='--', linewidth=3, label=ratio, marker='^', markersize=8)
ax1.set_ylabel('Ratio', fontsize=15)
ax1.legend(loc='best')
plt.show()
fig, axes = plt.subplots(6,1,figsize=(15,48))
color = ['b', 'g', 'r', 'c', 'm']
for RATIO in RATIOS:
for category in categories:
axes[RATIOS.index(RATIO)].plot('Time', category, data=SM_CC, color=color[categories.index(category)], linewidth=3, label=category, marker='.', markersize=12)
axes[RATIOS.index(RATIO)].set_xlabel('Date', fontsize=15)
axes[RATIOS.index(RATIO)].set_ylabel('The number of PPE', fontsize=15)
axes[RATIOS.index(RATIO)].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[RATIOS.index(RATIO)].legend(loc='best')
axes[RATIOS.index(RATIO)].set_title('The Ratio of PPE Dstribution to Confirmed Cases in Southeastern Massachusetts', fontsize=20)
ax1 = axes[RATIOS.index(RATIO)].twinx()
for ratio in RATIO:
ax1.plot('Time', ratio, data=SM_CC, color=color[RATIO.index(ratio)], linestyle='--', linewidth=3, label=ratio, marker='^', markersize=8)
ax1.set_ylabel('Ratio', fontsize=15)
ax1.legend(loc='best')
plt.show()
for category in categories:
SM_CC['{} delta'.format(category)] = SM_CC[category].diff()
SM_CC['Confirmed Cases delta'] = SM_CC['Confirmed Cases'].diff()
fig, axes = plt.subplots(2, 3, figsize=(29,15))
for ax, category in zip(axes.flatten(), categories):
sns.regplot('Confirmed Cases', category, data=SM_CC, ax=ax)
ax.set_xlabel('Confirmed Cases', fontsize=20)
ax.set_ylabel(category, fontsize=20)
ax.tick_params(direction='out', length=6, width=2, labelsize=12)
fig.delaxes(axes[1,2])
fig.suptitle('Regression Plot for Southeastern Massachusetts(Cumulative vs Cumulative)', fontsize=30)
fig1, axes1 = plt.subplots(2, 3, figsize=(25,15))
for ax, category in zip(axes1.flatten(), categories):
sns.regplot('Confirmed Cases delta', category + ' delta', data=SM_CC, ax=ax)
ax.set_xlabel('Confirmed Cases', fontsize=15)
ax.set_ylabel(category, fontsize=15)
fig1.delaxes(axes1[1,2])
fig1.suptitle('Regression Plot(delta vs delta)', fontsize=25)
# Regression Analysis
import statsmodels.api as sm
Y = [pd.DataFrame] * 5
X = [pd.DataFrame] * 5
for category in categories:
Y[categories.index(category)] = SM_CC[category]
X[categories.index(category)] = SM_CC['Confirmed Cases']
X[categories.index(category)] = sm.add_constant(X[categories.index(category)])
model = sm.OLS(Y[categories.index(category)], X[categories.index(category)])
results = model.fit()
print(results.summary())
NM = df.loc[df['Region']=='Northeastern Massachusetts']
NM_CC = NM.dropna()
categories = ['N95s/KN95s', 'Masks', 'Gowns', 'Gloves', 'Ventilators']
for category in categories:
NM_CC['{} %'.format(category)] = NM_CC[category]/NM_CC[category].iloc[-1] * 100
fig, axes = plt.subplots(2, 3, figsize=(25,15))
for ax, category in zip(axes.flatten(), categories):
sns.distplot(NM_CC[category].diff(), ax=ax)
ax.set_xlabel(category, fontsize=15)
fig.delaxes(axes[1,2])
NM_CC
# Confirmed cases vs PPE distribution
fig, axes = plt.subplots(2,1,figsize=(15,14))
percentages = ['N95s/KN95s %', 'Masks %', 'Gowns %', 'Gloves %', 'Ventilators %']
for category in categories:
axes[0].plot('Time', category, data=NM_CC, marker='.', markersize=10)
axes[0].set_xlabel('Date', fontsize=15)
axes[0].set_ylabel('The Number of PPE Distribution', fontsize=15)
axes[0].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[0].tick_params(direction='out', length=6, width=2, labelsize=10)
axes[0].legend()
axes[0].set_title('PPE Distribution vs Confirmed Cases in NM', fontsize=20)
ax1 = axes[0].twinx()
ax1.plot('Time', 'Confirmed Cases', data=NM_CC, color='y', linestyle='--', linewidth=3, label='Confirmed Cases')
ax1.set_ylabel('Confirmed Cases', fontsize=15)
ax1.tick_params(direction='out', length=6, width=2, labelsize=10)
ax1.legend(loc='upper right')
for percentage in percentages:
axes[1].plot('Time', percentage, data=NM_CC, marker='.', markersize=10)
axes[1].set_xlabel('Date', fontsize=15)
axes[1].set_ylabel('PPE Distribution %', fontsize=15)
axes[1].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[1].tick_params(direction='out', length=6, width=2, labelsize=10)
axes[1].legend()
axes[1].set_title('PPE Distribution Percentage vs Confirmed Cases in NM', fontsize=20)
ax2 = axes[1].twinx()
ax2.plot('Time', 'Confirmed Cases', data=NM_CC, color='y', linestyle='--', linewidth=3, label='Confirmed Cases')
ax2.set_ylabel('Confirmed Cases', fontsize=15)
ax2.tick_params(direction='out', length=6, width=2, labelsize=10)
ax2.legend(loc='upper right')
plt.show()
pd.set_option("display.max_rows", None, "display.max_columns", None)
# Calculate the ratio of cumulative PPE data to cumulative confirmed cases data (Ratio 1)
for category in categories:
NM_CC['{} Ratio 1'.format(category)] = NM_CC[category]/NM_CC['Confirmed Cases']
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 2)
# (Interval=2 weeks, one week before + the week itself)
NM_CC['Confirmed Cases(ma1)'] = NM_CC['Confirmed Cases'].rolling(window=2,center=False).mean()
NM_CC.iloc[0,-1] = (10641+14920) / 2
for category in categories:
NM_CC['{} Ratio 2'.format(category)] = NM_CC[category]/NM_CC['Confirmed Cases(ma1)']
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 3)
# (Interval=2 weeks, one week after + the week itself)
NM_CC['Confirmed Cases(ma2)'] = NM_CC['Confirmed Cases'].rolling(window=2,center=False).mean().shift(-1)
for category in categories:
NM_CC['{} Ratio 3'.format(category)] = NM_CC[category]/NM_CC['Confirmed Cases(ma2)']
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 4)
# (Interval=3 weeks, one week before + one week after + the week itself)
NM_CC['Confirmed Cases(ma3)'] = NM_CC['Confirmed Cases'].rolling(window=3,center=False).mean().shift(-1)
NM_CC.iloc[0,-1] = (10641+14920+18056)/3
for category in categories:
NM_CC['{} Ratio 4'.format(category)] = NM_CC[category]/NM_CC['Confirmed Cases(ma3)']
# Calculate the ratio of delta PPE data to delta confirmed cases data (Ratio 5)
for category in categories:
NM_CC['{} Ratio 5'.format(category)] = NM_CC[category].diff()/NM_CC['Confirmed Cases'].diff()
# Calculate the ratio of delta PPE data to moving average delta confirmed cases data (Ratio 6)
for category in categories:
NM_CC['{} Ratio 6'.format(category)] = NM_CC[category].diff()/NM_CC['Confirmed Cases'].diff().rolling(window=2,center=False).mean()
NM_CC
# Plot the Ratio of PPE to Confirmed Cases
RATIO1 = []
RATIO2 = []
RATIO3 = []
RATIO4 = []
RATIO5 = []
RATIO6 = []
RATIOS = [RATIO1, RATIO2, RATIO3, RATIO4, RATIO5, RATIO6]
for RATIO in RATIOS:
for category in categories:
RATIO.append('{} Ratio {}'.format(category, RATIOS.index(RATIO)+1))
fig, ax = plt.subplots(1,1,figsize=(14, 6))
color = ['b', 'g', 'r', 'c', 'm']
for category in categories:
ax.plot('Time', category, data=NM_CC, color=color[categories.index(category)], linewidth=3, label=category, marker='.', markersize=12)
ax.set_xlabel('Date', fontsize=15)
ax.set_ylabel('The number of PPE', fontsize=15)
ax.set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
ax.legend(loc='best')
ax.set_title('The Ratio of PPE Dstribution to Confirmed Cases in Northeastern Massachusetts', fontsize=20)
ax1 = ax.twinx()
for ratio in RATIO1:
ax1.plot('Time', ratio, data=NM_CC, color=color[RATIO1.index(ratio)], linestyle='--', linewidth=3, label=ratio, marker='^', markersize=8)
ax1.set_ylabel('Ratio', fontsize=15)
ax1.legend(loc='best')
plt.show()
fig, axes = plt.subplots(6,1,figsize=(15,48))
color = ['b', 'g', 'r', 'c', 'm']
for RATIO in RATIOS:
for category in categories:
axes[RATIOS.index(RATIO)].plot('Time', category, data=NM_CC, color=color[categories.index(category)], linewidth=3, label=category, marker='.', markersize=12)
axes[RATIOS.index(RATIO)].set_xlabel('Date', fontsize=15)
axes[RATIOS.index(RATIO)].set_ylabel('The number of PPE', fontsize=15)
axes[RATIOS.index(RATIO)].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[RATIOS.index(RATIO)].legend(loc='best')
axes[RATIOS.index(RATIO)].set_title('The Ratio of PPE Dstribution to Confirmed Cases in Northeastern Massachusetts', fontsize=20)
ax1 = axes[RATIOS.index(RATIO)].twinx()
for ratio in RATIO:
ax1.plot('Time', ratio, data=NM_CC, color=color[RATIO.index(ratio)], linestyle='--', linewidth=3, label=ratio, marker='^', markersize=8)
ax1.set_ylabel('Ratio', fontsize=15)
ax1.legend(loc='best')
plt.show()
for category in categories:
NM_CC['{} delta'.format(category)] = NM_CC[category].diff()
NM_CC['Confirmed Cases delta'] = NM_CC['Confirmed Cases'].diff()
fig, axes = plt.subplots(2, 3, figsize=(25,15))
for ax, category in zip(axes.flatten(), categories):
sns.regplot('Confirmed Cases', category, data=NM_CC, ax=ax)
ax.set_xlabel('Confirmed Cases', fontsize=15)
ax.set_ylabel(category, fontsize=15)
fig.delaxes(axes[1,2])
fig.suptitle('Regression Plot (Cumulative vs Cumulative)', fontsize=25)
fig1, axes1 = plt.subplots(2, 3, figsize=(25,15))
for ax, category in zip(axes1.flatten(), categories):
sns.regplot('Confirmed Cases delta', category + ' delta', data=NM_CC, ax=ax)
ax.set_xlabel('Confirmed Cases', fontsize=15)
ax.set_ylabel(category, fontsize=15)
fig1.delaxes(axes1[1,2])
fig1.suptitle('Regression Plot (Delta vs Delta)', fontsize=25)
import statsmodels.api as sm
Y = [pd.DataFrame] * 5
X = [pd.DataFrame] * 5
for category in categories:
Y[categories.index(category)] = NM_CC[category]
X[categories.index(category)] = NM_CC['Confirmed Cases']
X[categories.index(category)] = sm.add_constant(X[categories.index(category)])
model = sm.OLS(Y[categories.index(category)], X[categories.index(category)])
results = model.fit()
print(results.summary())
MW = df.loc[df['Region']=='Metro West']
MW_CC = MW.dropna()
categories = ['N95s/KN95s', 'Masks', 'Gowns', 'Gloves', 'Ventilators']
for category in categories:
MW_CC['{} %'.format(category)] = MW_CC[category]/MW_CC[category].iloc[-1] * 100
fig, axes = plt.subplots(2, 3, figsize=(25,15))
for ax, category in zip(axes.flatten(), categories):
sns.distplot(MW_CC[category].diff(), ax=ax)
ax.set_xlabel(category, fontsize=15)
fig.delaxes(axes[1,2])
MW_CC
# Confirmed cases vs PPE distribution
fig, axes = plt.subplots(2,1,figsize=(15,14))
percentages = ['N95s/KN95s %', 'Masks %', 'Gowns %', 'Gloves %', 'Ventilators %']
for category in categories:
axes[0].plot('Time', category, data=MW_CC, marker='.', markersize=10)
axes[0].set_xlabel('Date', fontsize=15)
axes[0].set_ylabel('The Number of PPE Distribution', fontsize=15)
axes[0].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[0].tick_params(direction='out', length=6, width=2, labelsize=10)
axes[0].legend()
axes[0].set_title('PPE Distribution vs Confirmed Cases in MW', fontsize=20)
ax1 = axes[0].twinx()
ax1.plot('Time', 'Confirmed Cases', data=MW_CC, color='y', linestyle='--', linewidth=3, label='Confirmed Cases')
ax1.set_ylabel('Confirmed Cases', fontsize=15)
ax1.tick_params(direction='out', length=6, width=2, labelsize=10)
ax1.legend(loc='upper right')
for percentage in percentages:
axes[1].plot('Time', percentage, data=MW_CC, marker='.', markersize=10)
axes[1].set_xlabel('Date', fontsize=15)
axes[1].set_ylabel('PPE Distribution %', fontsize=15)
axes[1].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[1].tick_params(direction='out', length=6, width=2, labelsize=10)
axes[1].legend()
axes[1].set_title('PPE Distribution Percentage vs Confirmed Cases in MW', fontsize=20)
ax2 = axes[1].twinx()
ax2.plot('Time', 'Confirmed Cases', data=MW_CC, color='y', linestyle='--', linewidth=3, label='Confirmed Cases')
ax2.set_ylabel('Confirmed Cases', fontsize=15)
ax2.tick_params(direction='out', length=6, width=2, labelsize=10)
ax2.legend(loc='upper right')
plt.show()
pd.set_option("display.max_rows", None, "display.max_columns", None)
# Calculate the ratio of cumulative PPE data to cumulative confirmed cases data (Ratio 1)
for category in categories:
MW_CC['{} Ratio 1'.format(category)] = MW_CC[category]/MW_CC['Confirmed Cases']
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 2)
# (Interval=2 weeks, one week before + the week itself)
MW_CC['Confirmed Cases(ma1)'] = MW_CC['Confirmed Cases'].rolling(window=2,center=False).mean()
MW_CC.iloc[0,-1] = (9219+12601) / 2
for category in categories:
MW_CC['{} Ratio 2'.format(category)] = MW_CC[category]/MW_CC['Confirmed Cases(ma1)']
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 3)
# (Interval=2 weeks, one week after + the week itself)
MW_CC['Confirmed Cases(ma2)'] = MW_CC['Confirmed Cases'].rolling(window=2,center=False).mean().shift(-1)
for category in categories:
MW_CC['{} Ratio 3'.format(category)] = MW_CC[category]/MW_CC['Confirmed Cases(ma2)']
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 4)
# (Interval=3 weeks, one week before + one week after + the week itself)
MW_CC['Confirmed Cases(ma3)'] = MW_CC['Confirmed Cases'].rolling(window=3,center=False).mean().shift(-1)
MW_CC.iloc[0,-1] = (9219+12601+14825)/3
for category in categories:
MW_CC['{} Ratio 4'.format(category)] = MW_CC[category]/MW_CC['Confirmed Cases(ma3)']
# Calculate the ratio of delta PPE data to delta confirmed cases data (Ratio 5)
for category in categories:
MW_CC['{} Ratio 5'.format(category)] = MW_CC[category].diff()/MW_CC['Confirmed Cases'].diff()
# Calculate the ratio of delta PPE data to moving average delta confirmed cases data (Ratio 6)
for category in categories:
MW_CC['{} Ratio 6'.format(category)] = MW_CC[category].diff()/MW_CC['Confirmed Cases'].diff().rolling(window=2,center=False).mean()
MW_CC
# Plot the Ratio of PPE to Confirmed Cases
RATIO1 = []
RATIO2 = []
RATIO3 = []
RATIO4 = []
RATIO5 = []
RATIO6 = []
RATIOS = [RATIO1, RATIO2, RATIO3, RATIO4, RATIO5, RATIO6]
for RATIO in RATIOS:
for category in categories:
RATIO.append('{} Ratio {}'.format(category, RATIOS.index(RATIO)+1))
fig, ax = plt.subplots(1,1,figsize=(14, 6))
color = ['b', 'g', 'r', 'c', 'm']
for category in categories:
ax.plot('Time', category, data=MW_CC, color=color[categories.index(category)], linewidth=3, label=category, marker='.', markersize=12)
ax.set_xlabel('Date', fontsize=15)
ax.set_ylabel('The number of PPE', fontsize=15)
ax.set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
ax.legend(loc='best')
ax.set_title('The Ratio of PPE Dstribution to Confirmed Cases in Southeastern Massachusetts', fontsize=20)
ax1 = ax.twinx()
for ratio in RATIO1:
ax1.plot('Time', ratio, data=MW_CC, color=color[RATIO1.index(ratio)], linestyle='--', linewidth=3, label=ratio, marker='^', markersize=8)
ax1.set_ylabel('Ratio', fontsize=15)
ax1.legend(loc='best')
plt.show()
fig, axes = plt.subplots(6,1,figsize=(15,48))
color = ['b', 'g', 'r', 'c', 'm']
for RATIO in RATIOS:
for category in categories:
axes[RATIOS.index(RATIO)].plot('Time', category, data=MW_CC, color=color[categories.index(category)], linewidth=3, label=category, marker='.', markersize=12)
axes[RATIOS.index(RATIO)].set_xlabel('Date', fontsize=15)
axes[RATIOS.index(RATIO)].set_ylabel('The number of PPE', fontsize=15)
axes[RATIOS.index(RATIO)].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[RATIOS.index(RATIO)].legend(loc='best')
axes[RATIOS.index(RATIO)].set_title('The Ratio of PPE Dstribution to Confirmed Cases in Metro West', fontsize=20)
ax1 = axes[RATIOS.index(RATIO)].twinx()
for ratio in RATIO:
ax1.plot('Time', ratio, data=MW_CC, color=color[RATIO.index(ratio)], linestyle='--', linewidth=3, label=ratio, marker='^', markersize=8)
ax1.set_ylabel('Ratio', fontsize=15)
ax1.legend(loc='best')
plt.show()
for category in categories:
MW_CC['{} delta'.format(category)] = MW_CC[category].diff()
MW_CC['Confirmed Cases delta'] = MW_CC['Confirmed Cases'].diff()
fig, axes = plt.subplots(2, 3, figsize=(25,15))
for ax, category in zip(axes.flatten(), categories):
sns.regplot('Confirmed Cases', category, data=MW_CC, ax=ax)
ax.set_xlabel('Confirmed Cases', fontsize=15)
ax.set_ylabel(category, fontsize=15)
fig.delaxes(axes[1,2])
fig.suptitle('Regression Plot (Cumulative vs Cumulative)', fontsize=25)
fig1, axes1 = plt.subplots(2, 3, figsize=(25,15))
for ax, category in zip(axes1.flatten(), categories):
sns.regplot('Confirmed Cases delta', category + ' delta', data=MW_CC, ax=ax)
ax.set_xlabel('Confirmed Cases', fontsize=15)
ax.set_ylabel(category, fontsize=15)
fig1.delaxes(axes1[1,2])
fig1.suptitle('Regression Plot (Delta vs Delta)', fontsize=25)
import statsmodels.api as sm
Y = [pd.DataFrame] * 5
X = [pd.DataFrame] * 5
for category in categories:
Y[categories.index(category)] = MW_CC[category]
X[categories.index(category)] = MW_CC['Confirmed Cases']
X[categories.index(category)] = sm.add_constant(X[categories.index(category)])
model = sm.OLS(Y[categories.index(category)], X[categories.index(category)])
results = model.fit()
print(results.summary())
MB = df.loc[df['Region']=='Metro Boston']
MB_CC = MB.dropna()
categories = ['N95s/KN95s', 'Masks', 'Gowns', 'Gloves', 'Ventilators']
for category in categories:
MB_CC['{} %'.format(category)] = MB_CC[category]/MB_CC[category].iloc[-1] * 100
fig, axes = plt.subplots(2, 3, figsize=(25,15))
for ax, category in zip(axes.flatten(), categories):
sns.distplot(MB_CC[category].diff(), ax=ax)
ax.set_xlabel(category, fontsize=15)
fig.delaxes(axes[1,2])
MB_CC
# Confirmed cases vs PPE distribution
fig, axes = plt.subplots(2,1,figsize=(15,14))
percentages = ['N95s/KN95s %', 'Masks %', 'Gowns %', 'Gloves %', 'Ventilators %']
for category in categories:
axes[0].plot('Time', category, data=MB_CC, marker='.', markersize=10)
axes[0].set_xlabel('Date', fontsize=15)
axes[0].set_ylabel('The Number of PPE Distribution', fontsize=15)
axes[0].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[0].tick_params(direction='out', length=6, width=2, labelsize=10)
axes[0].legend()
axes[0].set_title('PPE Distribution vs Confirmed Cases in MB', fontsize=20)
ax1 = axes[0].twinx()
ax1.plot('Time', 'Confirmed Cases', data=MB_CC, color='y', linestyle='--', linewidth=3, label='Confirmed Cases')
ax1.set_ylabel('Confirmed Cases', fontsize=15)
ax1.tick_params(direction='out', length=6, width=2, labelsize=10)
ax1.legend(loc='upper right')
for percentage in percentages:
axes[1].plot('Time', percentage, data=MB_CC, marker='.', markersize=10)
axes[1].set_xlabel('Date', fontsize=15)
axes[1].set_ylabel('PPE Distribution %', fontsize=15)
axes[1].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[1].tick_params(direction='out', length=6, width=2, labelsize=10)
axes[1].legend()
axes[1].set_title('PPE Distribution Percentage vs Confirmed Cases in MB', fontsize=20)
ax2 = axes[1].twinx()
ax2.plot('Time', 'Confirmed Cases', data=MB_CC, color='y', linestyle='--', linewidth=3, label='Confirmed Cases')
ax2.set_ylabel('Confirmed Cases', fontsize=15)
ax2.tick_params(direction='out', length=6, width=2, labelsize=10)
ax2.legend(loc='upper right')
plt.show()
pd.set_option("display.max_rows", None, "display.max_columns", None)
# Calculate the ratio of cumulative PPE data to cumulative confirmed cases data (Ratio 1)
for category in categories:
MB_CC['{} Ratio 1'.format(category)] = MB_CC[category]/MB_CC['Confirmed Cases']
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 2)
# (Interval=2 weeks, one week before + the week itself)
MB_CC['Confirmed Cases(ma1)'] = MB_CC['Confirmed Cases'].rolling(window=2,center=False).mean()
MB_CC.iloc[0,-1] = (9060+12539) / 2
for category in categories:
MB_CC['{} Ratio 2'.format(category)] = MB_CC[category]/MB_CC['Confirmed Cases(ma1)']
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 3)
# (Interval=2 weeks, one week after + the week itself)
MB_CC['Confirmed Cases(ma2)'] = MB_CC['Confirmed Cases'].rolling(window=2,center=False).mean().shift(-1)
for category in categories:
MB_CC['{} Ratio 3'.format(category)] = MB_CC[category]/MB_CC['Confirmed Cases(ma2)']
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 4)
# (Interval=3 weeks, one week before + one week after + the week itself)
MB_CC['Confirmed Cases(ma3)'] = MB_CC['Confirmed Cases'].rolling(window=3,center=False).mean().shift(-1)
MB_CC.iloc[0,-1] = (9060+12539+14476)/3
for category in categories:
MB_CC['{} Ratio 4'.format(category)] = MB_CC[category]/MB_CC['Confirmed Cases(ma3)']
# Calculate the ratio of delta PPE data to delta confirmed cases data (Ratio 5)
for category in categories:
MB_CC['{} Ratio 5'.format(category)] = MB_CC[category].diff()/MB_CC['Confirmed Cases'].diff()
# Calculate the ratio of delta PPE data to moving average delta confirmed cases data (Ratio 6)
for category in categories:
MB_CC['{} Ratio 6'.format(category)] = MB_CC[category].diff()/MB_CC['Confirmed Cases'].diff().rolling(window=2,center=False).mean()
MB_CC
# Plot the Ratio of PPE to Confirmed Cases
RATIO1 = []
RATIO2 = []
RATIO3 = []
RATIO4 = []
RATIO5 = []
RATIO6 = []
RATIOS = [RATIO1, RATIO2, RATIO3, RATIO4, RATIO5, RATIO6]
for RATIO in RATIOS:
for category in categories:
RATIO.append('{} Ratio {}'.format(category, RATIOS.index(RATIO)+1))
fig, axes = plt.subplots(6,1,figsize=(15,48))
color = ['b', 'g', 'r', 'c', 'm']
for RATIO in RATIOS:
for category in categories:
axes[RATIOS.index(RATIO)].plot('Time', category, data=MB_CC, color=color[categories.index(category)], linewidth=3, label=category, marker='.', markersize=12)
axes[RATIOS.index(RATIO)].set_xlabel('Date', fontsize=15)
axes[RATIOS.index(RATIO)].set_ylabel('The number of PPE', fontsize=15)
axes[RATIOS.index(RATIO)].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[RATIOS.index(RATIO)].legend(loc='best')
axes[RATIOS.index(RATIO)].set_title('The Ratio of PPE Dstribution to Confirmed Cases in Metro Boston', fontsize=20)
ax1 = axes[RATIOS.index(RATIO)].twinx()
for ratio in RATIO:
ax1.plot('Time', ratio, data=MB_CC, color=color[RATIO.index(ratio)], linestyle='--', linewidth=3, label=ratio, marker='^', markersize=8)
ax1.set_ylabel('Ratio', fontsize=15)
ax1.legend(loc='best')
plt.show()
for category in categories:
MB_CC['{} delta'.format(category)] = MB_CC[category].diff()
MB_CC['Confirmed Cases delta'] = MB_CC['Confirmed Cases'].diff()
fig, axes = plt.subplots(2, 3, figsize=(25,15))
for ax, category in zip(axes.flatten(), categories):
sns.regplot('Confirmed Cases', category, data=MB_CC, ax=ax)
ax.set_xlabel('Confirmed Cases', fontsize=15)
ax.set_ylabel(category, fontsize=15)
fig.delaxes(axes[1,2])
fig.suptitle('Regression Plot (Cumulative vs Cumulative)', fontsize=25)
fig1, axes1 = plt.subplots(2, 3, figsize=(25,15))
for ax, category in zip(axes1.flatten(), categories):
sns.regplot('Confirmed Cases delta', category + ' delta', data=MB_CC, ax=ax)
ax.set_xlabel('Confirmed Cases', fontsize=15)
ax.set_ylabel(category, fontsize=15)
fig1.delaxes(axes1[1,2])
fig1.suptitle('Regression Plot (Delta vs Delta)', fontsize=25)
import statsmodels.api as sm
Y = [pd.DataFrame] * 5
X = [pd.DataFrame] * 5
for category in categories:
Y[categories.index(category)] = MB_CC[category]
X[categories.index(category)] = MB_CC['Confirmed Cases']
X[categories.index(category)] = sm.add_constant(X[categories.index(category)])
model = sm.OLS(Y[categories.index(category)], X[categories.index(category)])
results = model.fit()
print(results.summary())
CM = df.loc[df['Region']=='Central Massachusetts']
CM_CC = CM.dropna()
categories = ['N95s/KN95s', 'Masks', 'Gowns', 'Gloves', 'Ventilators']
for category in categories:
CM_CC['{} %'.format(category)] = CM_CC[category]/CM_CC[category].iloc[-1] * 100
# fig, axes = plt.subplots(2, 3, figsize=(25,15))
# for ax, category in zip(axes.flatten(), categories):
# sns.distplot(CM_CC[category].diff(), ax=ax)
# ax.set_xlabel(category, fontsize=15)
# fig.delaxes(axes[1,2])
CM_CC
# Confirmed cases vs PPE distribution
fig, axes = plt.subplots(2,1,figsize=(15,14))
percentages = ['N95s/KN95s %', 'Masks %', 'Gowns %', 'Gloves %', 'Ventilators %']
for category in categories:
axes[0].plot('Time', category, data=CM_CC, marker='.', markersize=10)
axes[0].set_xlabel('Date', fontsize=15)
axes[0].set_ylabel('The Number of PPE Distribution', fontsize=15)
axes[0].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[0].tick_params(direction='out', length=6, width=2, labelsize=10)
axes[0].legend()
axes[0].set_title('PPE Distribution vs Confirmed Cases in CM', fontsize=20)
ax1 = axes[0].twinx()
ax1.plot('Time', 'Confirmed Cases', data=CM_CC, color='y', linestyle='--', linewidth=3, label='Confirmed Cases')
ax1.set_ylabel('Confirmed Cases', fontsize=15)
ax1.tick_params(direction='out', length=6, width=2, labelsize=10)
ax1.legend(loc='upper right')
for percentage in percentages:
axes[1].plot('Time', percentage, data=CM_CC, marker='.', markersize=10)
axes[1].set_xlabel('Date', fontsize=15)
axes[1].set_ylabel('PPE Distribution %', fontsize=15)
axes[1].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[1].tick_params(direction='out', length=6, width=2, labelsize=10)
axes[1].legend()
axes[1].set_title('PPE Distribution Percentage vs Confirmed Cases in CM', fontsize=20)
ax2 = axes[1].twinx()
ax2.plot('Time', 'Confirmed Cases', data=CM_CC, color='y', linestyle='--', linewidth=3, label='Confirmed Cases')
ax2.set_ylabel('Confirmed Cases', fontsize=15)
ax2.tick_params(direction='out', length=6, width=2, labelsize=10)
ax2.legend(loc='upper right')
plt.show()
pd.set_option("display.max_rows", None, "display.max_columns", None)
# Calculate the ratio of cumulative PPE data to cumulative confirmed cases data (Ratio 1)
for category in categories:
CM_CC['{} Ratio 1'.format(category)] = CM_CC[category]/CM_CC['Confirmed Cases']
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 2)
# (Interval=2 weeks, one week before + the week itself)
CM_CC['Confirmed Cases(ma1)'] = CM_CC['Confirmed Cases'].rolling(window=2,center=False).mean()
CM_CC.iloc[0,-1] = (3474+5363) / 2
for category in categories:
CM_CC['{} Ratio 2'.format(category)] = CM_CC[category]/CM_CC['Confirmed Cases(ma1)']
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 3)
# (Interval=2 weeks, one week after + the week itself)
CM_CC['Confirmed Cases(ma2)'] = CM_CC['Confirmed Cases'].rolling(window=2,center=False).mean().shift(-1)
for category in categories:
CM_CC['{} Ratio 3'.format(category)] = CM_CC[category]/CM_CC['Confirmed Cases(ma2)']
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 4)
# (Interval=3 weeks, one week before + one week after + the week itself)
CM_CC['Confirmed Cases(ma3)'] = CM_CC['Confirmed Cases'].rolling(window=3,center=False).mean().shift(-1)
CM_CC.iloc[0,-1] = (3474+5363+7056)/3
for category in categories:
CM_CC['{} Ratio 4'.format(category)] = CM_CC[category]/CM_CC['Confirmed Cases(ma3)']
# Calculate the ratio of delta PPE data to delta confirmed cases data (Ratio 5)
for category in categories:
CM_CC['{} Ratio 5'.format(category)] = CM_CC[category].diff()/CM_CC['Confirmed Cases'].diff()
# Calculate the ratio of delta PPE data to moving average delta confirmed cases data (Ratio 6)
for category in categories:
CM_CC['{} Ratio 6'.format(category)] = CM_CC[category].diff()/CM_CC['Confirmed Cases'].diff().rolling(window=2,center=False).mean()
CM_CC
# Plot the Ratio of PPE to Confirmed Cases
RATIO1 = []
RATIO2 = []
RATIO3 = []
RATIO4 = []
RATIO5 = []
RATIO6 = []
RATIOS = [RATIO1, RATIO2, RATIO3, RATIO4, RATIO5, RATIO6]
for RATIO in RATIOS:
for category in categories:
RATIO.append('{} Ratio {}'.format(category, RATIOS.index(RATIO)+1))
fig, axes = plt.subplots(6,1,figsize=(15,48))
color = ['b', 'g', 'r', 'c', 'm']
for RATIO in RATIOS:
for category in categories:
axes[RATIOS.index(RATIO)].plot('Time', category, data=CM_CC, color=color[categories.index(category)], linewidth=3, label=category, marker='.', markersize=12)
axes[RATIOS.index(RATIO)].set_xlabel('Date', fontsize=15)
axes[RATIOS.index(RATIO)].set_ylabel('The number of PPE', fontsize=15)
axes[RATIOS.index(RATIO)].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[RATIOS.index(RATIO)].legend(loc='best')
axes[RATIOS.index(RATIO)].set_title('The Ratio of PPE Dstribution to Confirmed Cases in Central Massachusetts', fontsize=20)
ax1 = axes[RATIOS.index(RATIO)].twinx()
for ratio in RATIO:
ax1.plot('Time', ratio, data=CM_CC, color=color[RATIO.index(ratio)], linestyle='--', linewidth=3, label=ratio, marker='^', markersize=8)
ax1.set_ylabel('Ratio', fontsize=15)
ax1.legend(loc='best')
plt.show()
for category in categories:
CM_CC['{} delta'.format(category)] = CM_CC[category].diff()
CM_CC['Confirmed Cases delta'] = CM_CC['Confirmed Cases'].diff()
fig, axes = plt.subplots(2, 3, figsize=(25,15))
for ax, category in zip(axes.flatten(), categories):
sns.regplot('Confirmed Cases', category, data=CM_CC, ax=ax)
ax.set_xlabel('Confirmed Cases', fontsize=15)
ax.set_ylabel(category, fontsize=15)
fig.delaxes(axes[1,2])
fig.suptitle('Regression Plot (Cumulative vs Cumulative)', fontsize=25)
fig1, axes1 = plt.subplots(2, 3, figsize=(25,15))
for ax, category in zip(axes1.flatten(), categories):
sns.regplot('Confirmed Cases delta', category + ' delta', data=CM_CC, ax=ax)
ax.set_xlabel('Confirmed Cases', fontsize=15)
ax.set_ylabel(category, fontsize=15)
fig1.delaxes(axes1[1,2])
fig1.suptitle('Regression Plot (Delta vs Delta)', fontsize=25)
import statsmodels.api as sm
Y = [pd.DataFrame] * 5
X = [pd.DataFrame] * 5
for category in categories:
Y[categories.index(category)] = CM_CC[category]
X[categories.index(category)] = CM_CC['Confirmed Cases']
X[categories.index(category)] = sm.add_constant(X[categories.index(category)])
model = sm.OLS(Y[categories.index(category)], X[categories.index(category)])
results = model.fit()
print(results.summary())
WM = df.loc[df['Region']=='Western Massachusetts']
WM_CC = WM.dropna()
categories = ['N95s/KN95s', 'Masks', 'Gowns', 'Gloves', 'Ventilators']
for category in categories:
WM_CC['{} %'.format(category)] = WM_CC[category]/WM_CC[category].iloc[-1] * 100
fig, axes = plt.subplots(2, 3, figsize=(25,15))
for ax, category in zip(axes.flatten(), categories):
sns.distplot(WM_CC[category].diff(), ax=ax)
ax.set_xlabel(category, fontsize=15)
fig.delaxes(axes[1,2])
WM_CC
# Confirmed cases vs PPE distribution
fig, axes = plt.subplots(2,1,figsize=(15,14))
percentages = ['N95s/KN95s %', 'Masks %', 'Gowns %', 'Gloves %', 'Ventilators %']
for category in categories:
axes[0].plot('Time', category, data=WM_CC, marker='.', markersize=10)
axes[0].set_xlabel('Date', fontsize=15)
axes[0].set_ylabel('The Number of PPE Distribution', fontsize=15)
axes[0].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[0].tick_params(direction='out', length=6, width=2, labelsize=10)
axes[0].legend()
axes[0].set_title('PPE Distribution vs Confirmed Cases in WM', fontsize=20)
ax1 = axes[0].twinx()
ax1.plot('Time', 'Confirmed Cases', data=WM_CC, color='y', linestyle='--', linewidth=3, label='Confirmed Cases')
ax1.set_ylabel('Confirmed Cases', fontsize=15)
ax1.tick_params(direction='out', length=6, width=2, labelsize=10)
ax1.legend(loc='upper right')
for percentage in percentages:
axes[1].plot('Time', percentage, data=WM_CC, marker='.', markersize=10)
axes[1].set_xlabel('Date', fontsize=15)
axes[1].set_ylabel('PPE Distribution %', fontsize=15)
axes[1].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[1].tick_params(direction='out', length=6, width=2, labelsize=10)
axes[1].legend()
axes[1].set_title('PPE Distribution Percentage vs Confirmed Cases in WM', fontsize=20)
ax2 = axes[1].twinx()
ax2.plot('Time', 'Confirmed Cases', data=WM_CC, color='y', linestyle='--', linewidth=3, label='Confirmed Cases')
ax2.set_ylabel('Confirmed Cases', fontsize=15)
ax2.tick_params(direction='out', length=6, width=2, labelsize=10)
ax2.legend(loc='upper right')
plt.show()
pd.set_option("display.max_rows", None, "display.max_columns", None)
# Calculate the ratio of cumulative PPE data to cumulative confirmed cases data (Ratio 1)
for category in categories:
WM_CC['{} Ratio 1'.format(category)] = WM_CC[category]/WM_CC['Confirmed Cases']
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 2)
# (Interval=2 weeks, one week before + the week itself)
WM_CC['Confirmed Cases(ma1)'] = WM_CC['Confirmed Cases'].rolling(window=2,center=False).mean()
WM_CC.iloc[0,-1] = (3763+5052) / 2
for category in categories:
WM_CC['{} Ratio 2'.format(category)] = WM_CC[category]/WM_CC['Confirmed Cases(ma1)']
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 3)
# (Interval=2 weeks, one week after + the week itself)
WM_CC['Confirmed Cases(ma2)'] = WM_CC['Confirmed Cases'].rolling(window=2,center=False).mean().shift(-1)
for category in categories:
WM_CC['{} Ratio 3'.format(category)] = WM_CC[category]/WM_CC['Confirmed Cases(ma2)']
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 4)
# (Interval=3 weeks, one week before + one week after + the week itself)
WM_CC['Confirmed Cases(ma3)'] = WM_CC['Confirmed Cases'].rolling(window=3,center=False).mean().shift(-1)
WM_CC.iloc[0,-1] = (3763+5052+5773)/3
for category in categories:
WM_CC['{} Ratio 4'.format(category)] = WM_CC[category]/WM_CC['Confirmed Cases(ma3)']
# Calculate the ratio of delta PPE data to delta confirmed cases data (Ratio 5)
for category in categories:
WM_CC['{} Ratio 5'.format(category)] = WM_CC[category].diff()/WM_CC['Confirmed Cases'].diff()
# Calculate the ratio of delta PPE data to moving average delta confirmed cases data (Ratio 6)
for category in categories:
WM_CC['{} Ratio 6'.format(category)] = WM_CC[category].diff()/WM_CC['Confirmed Cases'].diff().rolling(window=2,center=False).mean()
WM_CC
# Plot the Ratio of PPE to Confirmed Cases
RATIO1 = []
RATIO2 = []
RATIO3 = []
RATIO4 = []
RATIO5 = []
RATIO6 = []
RATIOS = [RATIO1, RATIO2, RATIO3, RATIO4, RATIO5, RATIO6]
for RATIO in RATIOS:
for category in categories:
RATIO.append('{} Ratio {}'.format(category, RATIOS.index(RATIO)+1))
fig, axes = plt.subplots(6,1,figsize=(15,48))
color = ['b', 'g', 'r', 'c', 'm']
for RATIO in RATIOS:
for category in categories:
axes[RATIOS.index(RATIO)].plot('Time', category, data=WM_CC, color=color[categories.index(category)], linewidth=3, label=category, marker='.', markersize=12)
axes[RATIOS.index(RATIO)].set_xlabel('Date', fontsize=15)
axes[RATIOS.index(RATIO)].set_ylabel('The number of PPE', fontsize=15)
axes[RATIOS.index(RATIO)].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[RATIOS.index(RATIO)].legend(loc='best')
axes[RATIOS.index(RATIO)].set_title('The Ratio of PPE Dstribution to Confirmed Cases in Western Massachusetts', fontsize=20)
ax1 = axes[RATIOS.index(RATIO)].twinx()
for ratio in RATIO:
ax1.plot('Time', ratio, data=WM_CC, color=color[RATIO.index(ratio)], linestyle='--', linewidth=3, label=ratio, marker='^', markersize=8)
ax1.set_ylabel('Ratio', fontsize=15)
ax1.legend(loc='best')
plt.show()
for category in categories:
WM_CC['{} delta'.format(category)] = WM_CC[category].diff()
WM_CC['Confirmed Cases delta'] = WM_CC['Confirmed Cases'].diff()
fig, axes = plt.subplots(2, 3, figsize=(25,15))
for ax, category in zip(axes.flatten(), categories):
sns.regplot('Confirmed Cases', category, data=WM_CC, ax=ax)
ax.set_xlabel('Confirmed Cases', fontsize=15)
ax.set_ylabel(category, fontsize=15)
fig.delaxes(axes[1,2])
fig.suptitle('Regression Plot (Cumulative vs Cumulative)', fontsize=25)
fig1, axes1 = plt.subplots(2, 3, figsize=(25,15))
for ax, category in zip(axes1.flatten(), categories):
sns.regplot('Confirmed Cases delta', category + ' delta', data=WM_CC, ax=ax)
ax.set_xlabel('Confirmed Cases', fontsize=15)
ax.set_ylabel(category, fontsize=15)
fig1.delaxes(axes1[1,2])
fig1.suptitle('Regression Plot (Delta vs Delta)', fontsize=25)
import statsmodels.api as sm
Y = [pd.DataFrame] * 5
X = [pd.DataFrame] * 5
for category in categories:
Y[categories.index(category)] = WM_CC[category]
X[categories.index(category)] = WM_CC['Confirmed Cases']
X[categories.index(category)] = sm.add_constant(X[categories.index(category)])
model = sm.OLS(Y[categories.index(category)], X[categories.index(category)])
results = model.fit()
print(results.summary())
MA_CC = df.loc[df['Region']=='Massachusetts'].dropna()
categories = ['N95s/KN95s', 'Masks', 'Gowns', 'Gloves', 'Ventilators']
for category in categories:
MA_CC['{} %'.format(category)] = MA_CC[category]/MA_CC[category].iloc[-1] * 100
# fig, axes = plt.subplots(2, 3, figsize=(25,15))
# for ax, category in zip(axes.flatten(), categories):
# sns.distplot(MA_CC[category].diff(), ax=ax)
# ax.set_xlabel(category, fontsize=15)
# fig.delaxes(axes[1,2])
MA_CC
# Confirmed cases vs PPE distribution
fig, axes = plt.subplots(2,1,figsize=(15,14))
percentages = ['N95s/KN95s %', 'Masks %', 'Gowns %', 'Gloves %', 'Ventilators %']
for category in categories:
axes[0].plot('Time', category, data=MA_CC, marker='.', markersize=10)
axes[0].set_xlabel('Date', fontsize=15)
axes[0].set_ylabel('The Number of PPE Distribution', fontsize=15)
axes[0].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[0].tick_params(direction='out', length=6, width=2, labelsize=10)
axes[0].legend()
axes[0].set_title('PPE Distribution vs Confirmed Cases in MA', fontsize=20)
ax1 = axes[0].twinx()
ax1.plot('Time', 'Confirmed Cases', data=MA_CC, color='y', linestyle='--', linewidth=3, label='Confirmed Cases')
ax1.set_ylabel('Confirmed Cases', fontsize=15)
ax1.tick_params(direction='out', length=6, width=2, labelsize=10)
ax1.legend(loc='upper right')
for percentage in percentages:
axes[1].plot('Time', percentage, data=MA_CC, marker='.', markersize=10)
axes[1].set_xlabel('Date', fontsize=15)
axes[1].set_ylabel('PPE Distribution %', fontsize=15)
axes[1].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[1].tick_params(direction='out', length=6, width=2, labelsize=10)
axes[1].legend()
axes[1].set_title('PPE Distribution Percentage vs Confirmed Cases in MA', fontsize=20)
ax2 = axes[1].twinx()
ax2.plot('Time', 'Confirmed Cases', data=MA_CC, color='y', linestyle='--', linewidth=3, label='Confirmed Cases')
ax2.set_ylabel('Confirmed Cases', fontsize=15)
ax2.tick_params(direction='out', length=6, width=2, labelsize=10)
ax2.legend(loc='upper right')
plt.show()
pd.set_option("display.max_rows", None, "display.max_columns", None)
# Calculate the ratio of cumulative PPE data to cumulative confirmed cases data (Ratio 1)
for category in categories:
MA_CC['{} Ratio 1'.format(category)] = MA_CC[category]/MA_CC['Confirmed Cases']
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 2)
# (Interval=2 weeks, one week before + the week itself)
MA_CC['Confirmed Cases(ma1)'] = MA_CC['Confirmed Cases'].rolling(window=2,center=False).mean()
MA_CC.iloc[0,-1] = (42944+60265) / 2
for category in categories:
MA_CC['{} Ratio 2'.format(category)] = MA_CC[category]/MA_CC['Confirmed Cases(ma1)']
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 3)
# (Interval=2 weeks, one week after + the week itself)
MA_CC['Confirmed Cases(ma2)'] = MA_CC['Confirmed Cases'].rolling(window=2,center=False).mean().shift(-1)
for category in categories:
MA_CC['{} Ratio 3'.format(category)] = MA_CC[category]/MA_CC['Confirmed Cases(ma2)']
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 4)
# (Interval=3 weeks, one week before + one week after + the week itself)
MA_CC['Confirmed Cases(ma3)'] = MA_CC['Confirmed Cases'].rolling(window=3,center=False).mean().shift(-1)
MA_CC.iloc[0,-1] = (42944+60265+72025)/3
for category in categories:
MA_CC['{} Ratio 4'.format(category)] = MA_CC[category]/MA_CC['Confirmed Cases(ma3)']
# Calculate the ratio of delta PPE data to delta confirmed cases data (Ratio 5)
for category in categories:
MA_CC['{} Ratio 5'.format(category)] = MA_CC[category].diff()/MA_CC['Confirmed Cases'].diff()
# Calculate the ratio of delta PPE data to moving average delta confirmed cases data (Ratio 6)
for category in categories:
MA_CC['{} Ratio 6'.format(category)] = MA_CC[category].diff()/MA_CC['Confirmed Cases'].diff().rolling(window=2,center=False).mean()
MA_CC
# Plot the Ratio of PPE to Confirmed Cases
RATIO1 = []
RATIO2 = []
RATIO3 = []
RATIO4 = []
RATIO5 = []
RATIO6 = []
RATIOS = [RATIO1, RATIO2, RATIO3, RATIO4, RATIO5, RATIO6]
for RATIO in RATIOS:
for category in categories:
RATIO.append('{} Ratio {}'.format(category, RATIOS.index(RATIO)+1))
fig, axes = plt.subplots(6,1,figsize=(15,48))
color = ['b', 'g', 'r', 'c', 'm']
for RATIO in RATIOS:
for category in categories:
axes[RATIOS.index(RATIO)].plot('Time', category, data=MA_CC, color=color[categories.index(category)], linewidth=3, label=category, marker='.', markersize=12)
axes[RATIOS.index(RATIO)].set_xlabel('Date', fontsize=15)
axes[RATIOS.index(RATIO)].set_ylabel('The number of PPE', fontsize=15)
axes[RATIOS.index(RATIO)].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[RATIOS.index(RATIO)].legend(loc='best')
axes[RATIOS.index(RATIO)].set_title('The Ratio of PPE Dstribution to Confirmed Cases in Massachusetts', fontsize=20)
ax1 = axes[RATIOS.index(RATIO)].twinx()
for ratio in RATIO:
ax1.plot('Time', ratio, data=MA_CC, color=color[RATIO.index(ratio)], linestyle='--', linewidth=3, label=ratio, marker='^', markersize=8)
ax1.set_ylabel('Ratio', fontsize=15)
ax1.legend(loc='best')
plt.show()
for category in categories:
MA_CC['{} delta'.format(category)] = MA_CC[category].diff()
MA_CC['Confirmed Cases delta'] = MA_CC['Confirmed Cases'].diff()
fig, axes = plt.subplots(2, 3, figsize=(25,15))
for ax, category in zip(axes.flatten(), categories):
sns.regplot('Confirmed Cases', category, data=MA_CC, ax=ax)
ax.set_xlabel('Confirmed Cases', fontsize=15)
ax.set_ylabel(category, fontsize=15)
fig.delaxes(axes[1,2])
fig.suptitle('Regression Plot (Cumulative vs Cumulative)', fontsize=25)
fig1, axes1 = plt.subplots(2, 3, figsize=(25,15))
for ax, category in zip(axes1.flatten(), categories):
sns.regplot('Confirmed Cases delta', category + ' delta', data=MA_CC, ax=ax)
ax.set_xlabel('Confirmed Cases', fontsize=15)
ax.set_ylabel(category, fontsize=15)
fig1.delaxes(axes1[1,2])
fig1.suptitle('Regression Plot (Delta vs Delta)', fontsize=25)
import statsmodels.api as sm
Y = [pd.DataFrame] * 5
X = [pd.DataFrame] * 5
for category in categories:
Y[categories.index(category)] = MA_CC[category]
X[categories.index(category)] = MA_CC['Confirmed Cases']
X[categories.index(category)] = sm.add_constant(X[categories.index(category)])
model = sm.OLS(Y[categories.index(category)], X[categories.index(category)])
results = model.fit()
print(results.summary())